﻿using System;
using iTeamyou.LTS.Core.Models;
using Microsoft.Extensions.Logging;

namespace iTeamyou.LTS.Core.Services
{
	public class SupplierAttachmentService
	{
        public MainDBContext _dbContext;
        private readonly ILogger<SupplierAttachmentService> _logger;

        public SupplierAttachmentService(MainDBContext dbContext, ILogger<SupplierAttachmentService> logger)
        {
            _dbContext = dbContext;
            _logger = logger;
        }
        public SupplierLicenseAttachment Get(string licenseId)
        {
            return _dbContext.SupplierLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).FirstOrDefault();
        }

        public List<SupplierLicenseAttachment> GetList(string licenseId, bool isMain)
        {
            if (isMain)
                return _dbContext.SupplierLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).ToList();
            else
                return _dbContext.SupplierLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == false).ToList();
        }
    }

    public class ProductAttachmentService
    {
        public MainDBContext _dbContext;
        private readonly ILogger<ProductAttachmentService> _logger;

        public ProductAttachmentService(MainDBContext dbContext, ILogger<ProductAttachmentService> logger)
        {
            _dbContext = dbContext;
            _logger = logger;
        }
        public ProductLicenseAttachment Get(string licenseId)
        {
            return _dbContext.ProductLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).FirstOrDefault();
        }

        public List<ProductLicenseAttachment> GetList(string licenseId, bool isMain)
        {
            if (isMain)
                return _dbContext.ProductLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).ToList();
            else
                return _dbContext.ProductLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == false).ToList();
        }
    }

    public class ManufacturerAttachmentService
    {
        public MainDBContext _dbContext;
        private readonly ILogger<ManufacturerAttachmentService> _logger;

        public ManufacturerAttachmentService(MainDBContext dbContext, ILogger<ManufacturerAttachmentService> logger)
        {
            _dbContext = dbContext;
            _logger = logger;
        }
        public ManufacturerLicenseAttachment Get(string licenseId)
        {
            return _dbContext.ManufacturerLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).FirstOrDefault();
        }

        public List<ManufacturerLicenseAttachment> GetList(string licenseId, bool isMain)
        {
            if (isMain)
                return _dbContext.ManufacturerLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).ToList();
            else
                return _dbContext.ManufacturerLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == false).ToList();
        }
    }

    public class BatchAttachmentService
    {
        public MainDBContext _dbContext;
        private readonly ILogger<BatchAttachmentService> _logger;

        public BatchAttachmentService(MainDBContext dbContext, ILogger<BatchAttachmentService> logger)
        {
            _dbContext = dbContext;
            _logger = logger;
        }
        public BatchLicenseAttachment Get(string licenseId)
        {
            return _dbContext.BatchLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).FirstOrDefault();
        }

        public List<BatchLicenseAttachment> GetList(string licenseId, bool isMain)
        {
            if (isMain)
                return _dbContext.BatchLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == true).ToList();
            else
                return _dbContext.BatchLicenseAttachments.Where(a => a.LicenseId == licenseId && a.IsMain == false).ToList();
        }
    }
}

